package com.knowledge.action;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.knowledge.DAO.DBpool;
import com.knowledge.model.Knowledge;
import com.opensymphony.xwork2.ActionSupport;

public class EditAction extends ActionSupport {
	private String knowledgeId;
	Knowledge knowledge=new Knowledge();


	public String getKnowledgeId() {
		return knowledgeId;
	}


	public void setKnowledgeId(String knowledgeId) {
		this.knowledgeId = knowledgeId;
	}


	public Knowledge getKnowledge() {
		return knowledge;
	}


	public void setKnowledge(Knowledge knowledge) {
		this.knowledge = knowledge;
	}


	@Override
	public String execute() throws Exception {
		
		Connection con = DBpool.getConnection();
		PreparedStatement stm = null;
		ResultSet rs=null;
		
		String sql="select title, content " +
				   "from knowledge " +
				   "where id=? ";
		try{
		stm=con.prepareStatement(sql);
		stm.setString(1, knowledgeId);
		rs=stm.executeQuery();
		
		while(rs.next())
		{
			knowledge.setTitle(rs.getString(1));
			knowledge.setContent(rs.getString(2));
		}
		
		con.close();
		stm.close();
		rs.close();
		
		}catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "success";
	}
	
	
	
}
